<?php

/**
 * Name: 问题清单验证层
 * User: Silent
 * Date: 2025-09-20
 * Time: 22:43:18
 */

namespace App\Http\Requests\Safety;

use Illuminate\Foundation\Http\FormRequest;

class QuestionRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $rules = [
            'region'      => 'required|string',
            'description' => 'required|string',
            'notes'       => 'required|string',
        ];

        $action = optional($this->route())->getActionMethod();
        if ($action === 'update') {
            $rules['id'] = 'required|integer';
        }

        return $rules;
    }

    public function messages(): array
    {
        return [
            'region.required'      => '区域不能为空',
            'description.required' => '问题描述不能为空',
            'notes.required'       => '备注不能为空',
            'id.required'          => 'ID不能为空',
            'id.integer'           => 'ID必须为整数',
        ];
    }
}
